package com.maxd.respository.helpTask;

import com.maxd.model.HelpTakeOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

public interface HelpTakeOrderRepository extends Repository<HelpTakeOrder, Long> {

    @Transactional
    @Modifying
    @Query(value = "update help_take_order t set t.state=:state,t.audit_content=:auditContent,category=:category where t.id=:id",nativeQuery = true)
    Integer updateHelpTakeOrder(@Param("state") Integer state, @Param("id") Long id,@Param("auditContent") String auditContent,@Param("category") Integer category);

    @Query(value = "select * from help_take_order t where t.help_task_id=:helpTaskId",nativeQuery = true)
    HelpTakeOrder selectHelpTakeOrderByHelpTaskId(@Param("helpTaskId") Long helpTaskId);

    @Query(value = "select * from help_take_order t where t.help_task_id=:helpTaskId and t.user_id=:userId",nativeQuery = true)
    Integer selectCountByHelpTaskIdAndUserId(@Param("helpTaskId") Long helpTaskId,@Param("userId") Long userId);


    @Query(value = "select * from help_take_order t where t.id=:helpTakeOrderId ",nativeQuery = true)
    HelpTakeOrder selectById(@Param("helpTakeOrderId") Long helpTakeOrderId);


}
